/**
 * 
 */
$(document).ready(function() {
	//$('#new_address').hide();
	initialize();
});

function initialize()
{
	user_op_address(false);
	bind_cart_click(false); 
}
    
function choose_address(this_obj,call_ws){
        
        this_obj.parent().parent().parent().find('p').css('color','#000');
         
        var add_code = this_obj.val();
        if(add_code=='new_address')
        {
           if(call_ws) 
              _lt_click_stat($(this).attr('lt_stat_id'));
              
           $('#hidden_address').css('display','none').find('table tbody tr td input').attr('value','');
           address_select = new address_list($('#province_slt'),$('#city_slt'),$('#area_slt'),{callback:show_addr_select,auto_disable:true});
           
           set_cod_area_disply(false);
           
           $('#hidden_address .table_address').removeClass("table_address_focus");
           $('#hidden_address').insertAfter(this_obj.parent().parent()).css('display','block');
           $('#hidden_address table tr td').find('span').text("").removeClass("rightmessage").removeClass('wrongmessage').removeClass('wrongmessagefocus');
           $('#btn_save').parent().parent().css('display','none');

        }
        else{
            
            this_obj.parent().parent().css('color','#cc3300');
            $('#hidden_address').insertAfter('.paybody:last').css('display','none');
            get_order_transfer(add_code);
        }
        //地址中修改地址的时候控制修改和取消按钮的切换
        $('#reciever_list p:eq('+ current_op_address +')').find('span:last > a:eq(0)').text("修改");
        current_op_address = -1;
        is_vif = false;
        
       
    }

function user_op_address(call_ws){
    
    //用户选择收货地址时候的操作
	var address = $("input[name='radio_address']")
	address.change(radioValueChanged);
}


function radioValueChanged()
{
    radioValue = $(this).val();
    if($(this).is(":checked") && radioValue == "new_address")
    {
        $('#new_address').show();
    }
    else
    {
        $('#new_address').hide();
    }
}

function ProdCountHover(){
    $(".add_product").hover(
        function(){
            $(this).addClass("add_product_hover");
        },
        function(){
            $(this).removeClass("add_product_hover");
        }
    );
    $(".remove_product").hover(
        function(){
            $(this).addClass("remove_product_hover");
        },
        function(){
            $(this).removeClass("remove_product_hover");
        }
    );
}

function refreshCartAccount(){
	$.each($("#checkout_cart_table .product_count input"),function(){
		var tr = $(this).closest("tr");
		var product_count_span = tr.find(".product_count")
		var price = parseInt(tr.find(".product_price_span").text());
	})
}

function InputFocus(){
    $(".shortinput, .midinput, .longinput").focus(
        function(){
            $(this).css({
                "border-color":"#008cd6",
                "color":"#008cd6"
            });
        }
    ).blur(
        function(){
            $(this).css({
                "border-color":"#999",
                "color":"#000"
            });
        }
    );
}
function bind_cart_click(call_ws){
	ProdCountHover();
	InputFocus();
}
function addFood(intFoodId, intQuantity)
{
	var actionURL = "/index.php/checkOutCart/addFood/" + intFoodId + "/"+intQuantity;
	sendUrl("addFoodToCart", actionURL);	
}


function substractFood(intFoodId, intQuantity)
{
	var actionURL = "/index.php/checkOutCart/substractFood/" + intFoodId + "/"+intQuantity;
	sendUrl("substractFood", actionURL);	
}

function removeFood(intFoodId)
{
	var actionURL = "/index.php/checkOutCart/removeFood/" + intFoodId;
	sendUrl("removeFood", actionURL);
}

function sendUrl(actionName, actionURL) {
	$('#check_out_cart_ajax_loading_div').show();
	$('#checkout_cart_table').addClass('check_out_cart_table_transparent');
	$.ajax({
	//Vancl_ajax({
	  url: actionURL,
	  cache:false,
	  type:"POST",
	  success: function(checkoutCartHtml){
//		alert(actionName + "success cart");
		$("#check_out_cart_wrapper_div").html(checkoutCartHtml);
		initialize();
	  },
	  complete:function(){
		  $('#check_out_cart_ajax_loading_div').hide();
		  $('#checkout_cart_table').removeClass('check_out_cart_table_transparent');
	  }
	});
}

